﻿USE [master]
GO
/****** Object:  Database [HabraStats]    Script Date: 19.10.2012 12:16:59 ******/
CREATE DATABASE [HabraStats]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'HabraStats', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\HabraStats.mdf' , SIZE = 2129920KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10240KB )
 LOG ON 
( NAME = N'HabraStats_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\HabraStats_log.ldf' , SIZE = 29504KB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
GO
ALTER DATABASE [HabraStats] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [HabraStats].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [HabraStats] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [HabraStats] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [HabraStats] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [HabraStats] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [HabraStats] SET ARITHABORT OFF 
GO
ALTER DATABASE [HabraStats] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [HabraStats] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [HabraStats] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [HabraStats] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [HabraStats] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [HabraStats] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [HabraStats] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [HabraStats] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [HabraStats] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [HabraStats] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [HabraStats] SET  DISABLE_BROKER 
GO
ALTER DATABASE [HabraStats] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [HabraStats] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [HabraStats] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [HabraStats] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [HabraStats] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [HabraStats] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [HabraStats] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [HabraStats] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [HabraStats] SET  MULTI_USER 
GO
ALTER DATABASE [HabraStats] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [HabraStats] SET DB_CHAINING OFF 
GO
ALTER DATABASE [HabraStats] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [HabraStats] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
USE [HabraStats]
GO
/****** Object:  User [NT AUTHORITY\SYSTEM]    Script Date: 19.10.2012 12:17:00 ******/
CREATE USER [NT AUTHORITY\SYSTEM] FOR LOGIN [NT AUTHORITY\SYSTEM] WITH DEFAULT_SCHEMA=[dbo]
GO
ALTER ROLE [db_datareader] ADD MEMBER [NT AUTHORITY\SYSTEM]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [NT AUTHORITY\SYSTEM]
GO
/****** Object:  Table [dbo].[Comments]    Script Date: 19.10.2012 12:17:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Comments](
	[Id] [int] NOT NULL,
	[Text] [nvarchar](max) NOT NULL,
	[PostId] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
	[Score] [int] NOT NULL,
	[ScorePlus] [int] NOT NULL,
	[UserName] [nvarchar](200) NOT NULL,
	[Avatar] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_Comments] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Posts]    Script Date: 19.10.2012 12:17:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Posts](
	[Id] [int] NOT NULL,
	[Title] [nvarchar](1000) NOT NULL,
	[Score] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
 CONSTRAINT [PK_Post] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Index [IX_PostId]    Script Date: 19.10.2012 12:17:00 ******/
CREATE NONCLUSTERED INDEX [IX_PostId] ON [dbo].[Comments]
(
	[PostId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [IX_Score]    Script Date: 19.10.2012 12:17:00 ******/
CREATE NONCLUSTERED INDEX [IX_Score] ON [dbo].[Comments]
(
	[Score] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [NonClusteredIndex-20121007-212623]    Script Date: 19.10.2012 12:17:00 ******/
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20121007-212623] ON [dbo].[Comments]
(
	[Date] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Comments]  WITH CHECK ADD  CONSTRAINT [FK_Comments_Post] FOREIGN KEY([PostId])
REFERENCES [dbo].[Posts] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Comments] CHECK CONSTRAINT [FK_Comments_Post]
GO
USE [master]
GO
ALTER DATABASE [HabraStats] SET  READ_WRITE 
GO
